package com.karolak.stock.oscilator;

import com.karolak.stock.data.DataManager;
import com.karolak.stock.indicator.Indicator;

public class SwitchOsc extends Oscilator {

	private Indicator high;
	private Indicator low;
	private Indicator lastHigh;
	private Indicator lastLow;	

	public SwitchOsc(String name, DataManager dataManager, Indicator input0, Indicator high, Indicator low, Indicator lastHigh, Indicator lastLow) {
		super(dataManager, 0, input0);
		this.high = high;
		this.low = low;
		this.lastHigh = lastHigh;
		this.lastLow = lastLow;
		setName(name);
	}

	@Override
	public double execute(double x) {
		double osc = getDataManager().getLast(getInput().getName());
		double high = getDataManager().getLast(getHigh().getName());
		double low = getDataManager().getLast(getLow().getName());

//		double lastHigh = getDataManager().getLast(getLastHigh().getName());
//		double lastLow = getDataManager().getLast(getLastLow().getName());

		double crossCtr = getDataManager().getLast(getLastHigh().getName());
//		double lastLow = getDataManager().getLast(getLastLow().getName());

		
		if (Math.abs(high) < 0.0002 && Math.abs(low) < 0.0002) {
			return 0;
		}
//
		if (0 < high) {
			return 1;
		}
//
		if (low < 0) {
			return 1;
		}
//
		if ( crossCtr < 10) {
//			if (lastHigh < low) {
				return 0.5;
//			}
//			if (high < lastLow) {
//				return 0.5;
//			}
		}
		
//		if (0 < high && lastHigh < low ) {
//			return 1;
//		}
//		if (low < 0 &&  high < lastLow) {
//			return -1;
//		}
		
		return 0;
	}

	protected Indicator getHigh() {
		return high;
	}

	protected Indicator getLow() {
		return low;
	}

	protected Indicator getLastHigh() {
		return lastHigh;
	}

	protected Indicator getLastLow() {
		return lastLow;
	}
}
